package com.zb.controller;


import com.zb.entity.dto.FactoryOrderByFieldDto;
import com.zb.entity.dto.OrderByFieldDto;
import com.zb.result.Result;
import com.zb.service.ZjAdmFactoryOrderByFieldService;
import com.zb.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 后台厂商工单列表排序字段表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-04-10
 */
@Api(tags = "品牌厂商工单列表排序类接口")
@RestController
@RequestMapping("/factory/order/by/field")
public class ZjAdmFactoryOrderByFieldController {
    @Resource
    private ZjAdmFactoryOrderByFieldService admFactoryOrderByFieldService;

    @ApiOperation("新增或修改工单列表排序字段")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid FactoryOrderByFieldDto fieldDto) {
        admFactoryOrderByFieldService.save(fieldDto);
        return Result.success(null == fieldDto.getId()? "新增排序字段类型成功" : "修改排序字段类型成功");
    }

    @ApiOperation("获取排序字段列表")
    @PostMapping("/getList")
    public Result getList(@RequestBody PageUtil pageUtil) {
        return Result.success("获取排序字段列表成功").data(admFactoryOrderByFieldService.getList(pageUtil));
    }

    @ApiOperation("根据排序字段ID获取详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "排序字段ID", required = true) Long id) {
        return Result.success("获取详情成功").data(PageUtil.row(admFactoryOrderByFieldService.getDetail(id)));
    }

    @ApiOperation("批量启用或禁用排序字段")
    @PostMapping("/disabled")
    public Result disabled(@RequestParam @ApiParam(value = "排序字段状态：false-启用，true-禁用", required = true) boolean status,
                           @RequestBody @ApiParam(value = "排序字段ID", required = true) List<Long> ids) {
        admFactoryOrderByFieldService.updateDisabledBatchById(ids, status);
        return Result.success(status? "禁用排序字段成功" : "启用排序字段成功");
    }

}
